package com.example.anpapi.entity.po.usermodel.User;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum UserRole {

    READER("READER", "读者"),
    AUTHOR("AUTHOR", "作者"),
    ADMIN("ADMIN", "管理员");

    @EnumValue
    private final String code;

    @JsonValue
    private final String description;

    UserRole(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取枚举
     */
    public static UserRole getByCode(String code) {
        for (UserRole role : values()) {
            if (role.getCode().equals(code)) {
                return role;
            }
        }
        return READER;
    }

    @Override
    public String toString() {
        return this.code;
    }
}
